package cn.edu.hbwe.book.admin.servlet.notices;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.hbwe.book.admin.service.notices.NoticesService;
import cn.edu.hbwe.book.entity.Notice;

/**
 * Servlet implementation class EditNoticeServlet
 */
public class EditNoticeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		NoticesService nService = new NoticesService();
		Notice n = new Notice();
		// 获取表单参数
		int n_id = Integer.parseInt(request.getParameter("id"));
		String title = request.getParameter("title");
		String details = request.getParameter("details");

		// 将当前时间设为添加公告的时间
		String t = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

		n.setN_id(n_id);
		n.setTitle(title);
		n.setDetails(details);
		n.setN_time(t);

		nService.updateNotice(n);

		request.getRequestDispatcher("/NoticeListServlet").forward(request, response);
	}

}
